package org.jeecgframework.web.material.service.impl;
import java.util.ArrayList;
import java.util.List;

import org.jeecgframework.core.annotation.Ehcache;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.ComboTree;
import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.tag.vo.easyui.ComboTreeModel;
import org.jeecgframework.web.material.entity.PTypeEntity;
import org.jeecgframework.web.material.service.PTypeServiceI;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("pTypeService")
@Transactional
public class PTypeServiceImpl extends CommonServiceImpl implements PTypeServiceI {

	/**
	 * 获取产品分类树
	 */
	//增加缓存
	@Ehcache(cacheName="PTypeEntityCache")
	public List<ComboTree> getComboTree(ComboTree comboTree) {
		CriteriaQuery cq = new CriteriaQuery(PTypeEntity.class);
		if (comboTree.getId() != null) {
			cq.eq("parentId.id", comboTree.getId());
		}
		if (comboTree.getId() == null) {
			cq.isNull("parentId");
		}
		cq.add();
		List<PTypeEntity> ptypeList = this.getListByCriteriaQuery(cq, false);
		List<ComboTree> comboTrees = new ArrayList<ComboTree>();
		ComboTreeModel comboTreeModel = new ComboTreeModel("id", "name", "childPtypes");
		comboTrees = this.ComboTree(ptypeList, comboTreeModel, null, true);
		return comboTrees;
	}


}